﻿<%@ Page Inherits="Mysoft.Crm.Web.Search.SearchPage" Language="vb" CodeBehind="Mysoft.Crm.Application.Pages.Search.dll" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Crm.Application.Menus" Assembly="Mysoft.Crm.Application.Components" %>
<%@ Register TagPrefix="crm" Namespace="Mysoft.Crm.Controls" Assembly="Mysoft.Crm.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Crm.Application.Controls" Assembly="Mysoft.Crm.Application.Components" %>
<%@ Import Namespace="Mysoft.Crm"%>
<html>
<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"/>
<cnt:AppHeader id="crmHeader" runat="server" />
<script language="JavaScript" src="/_tools/search/search.js"></script>
<script language="JavaScript">

	var _sViewId = "<%= viewId %>";

	function window.onload()
	{	
		self.focus();

		InitCalendar(ORG_DATE_FORMAT, ORG_DATE_SEPARATOR, ORG_DATE_START_DAY);

		var oXml	= new ActiveXObject("Microsoft.XMLDOM");
		oXml.async	= false;
		oXml.loadXML(_sValueXml);

		_oValueNode = oXml.selectSingleNode("*");	
	
		UpdateSearchControl( "<%=_DefaultObjectTypeCode.ToString()%>", "<%=Util.GetObjName(_DefaultObjectTypeCode)%>" );
	}

	// Updates the search control based on a new object type.
	// NOTE:  This function assumes that the _iNumFilters, _sLayoutXml, and sIdFieldName have been
	// properly set already for the new object type.
	function UpdateSearchControl( sObjectType, sObjectName )
	{
		var oArgs = new Object();

		oArgs.iNumFilters	= _iNumFilters;
		oArgs.sObjectType	= sObjectType;
		oArgs.sObjectName	= sObjectName;
		oArgs.sLayoutXml	= _sLayoutXml;
		oArgs.sIdFieldName	= _sIdFieldName;
		oArgs.bShowHeaders	= false;

		loadSearch(oArgs);		
	}
	

	function onObjectChange(o)
	{
		var a = o.returnValue.split(/,/g);

		var sObjectType	= a[0];
		var sObjectName	= a[1];

		getDefaultView(sObjectType);
			
		UpdateSearchControl( sObjectType, sObjectName );
	}


	function getDefaultView(iObjectType)
	{
		var oXml	= new ActiveXObject("Microsoft.XMLDOM");
		oXml.async	= false;

		oXml.load("getview.aspx?obj=" + iObjectType);

		_sViewId		= oXml.selectSingleNode("/resultset/result/savedqueryid").text;

		oXml.loadXML(oXml.selectSingleNode("/resultset/result/layoutxml").text);

		var oNode		= oXml.selectSingleNode("/grid");
		_sLayoutXml		= oNode.xml;
		_sIdFieldName	= oNode.selectSingleNode("row").attributes.getNamedItem("id").value;

		resultFrame.navigate("fetchData.aspx?viewId=" + _sViewId + "&objType=" + iObjectType);
	}
	
	function buildFetch()
	{
		var sFetch = getFetchXml(false);

		if (sFetch != "")
		{
			resultFrame.crmGrid.frmGrid.suppressFetch.value = false;
			resultFrame.crmGrid.frmGrid.fetchXml.value		= sFetch;
			resultFrame.crmGrid.frmGrid.pageNum.value		= 1;
			resultFrame.crmGrid.frmGrid.submit();
		}
		else
		{
			return;
		}
	}
	
	function reset()
	{
		resultFrame.navigate("fetchData.aspx?viewId=" + _sViewId + "&objType=" + _sObjectType);
		resetSearch();
	}

</script>
<style>

	BUTTON
	{
		width:	80px;
	}

	TD.gridspacer
	{
		width:				5px;
	}

	TD.gridheader
	{
		padding-left:		8px;
	}

	TABLE.gridheader
	{
		background-color:	#e9e7d7;
		background-image:	url(/_grid/imgs/bar_bk.gif);
		font-size:			11px;
		width:				100%;
		height:				22px;
		border:				1px solid #dbdac9;
		border-bottom:		1px solid #c5c1b1;
	}

</style>
<title>Advanced Find</title>
<link rel="stylesheet" type="text/css" href="/_tools/search/search.css">
</head>
<body>

	<table height="100%" width="100%" cellpadding="0" cellspacing="0">
		<tr height="23">
			<td colspan="2"><mnu:AppGenericMenuBar id="crmMenuBar" ShowToolBar="false" runat="server"/></td>
		</tr>
		<tr height="10" style="padding:10px;padding-bottom:0px;">
			<td>
				<table width="100%" cellpadding="5" cellspacing="0">
					<tr>
						<td colspan="2" style="border-bottom:1px solid #cccccc;">
							<table width="270" cellpadding="5" cellspacing="0" style="table-layout:fixed">
							<col width="70"><col>
								<tr>
									<td>Find in:</td>
									<td id="tdObjSelectList"><crm:Select id="objSelect" EventHandler="onObjectChange" runat="server"/></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table height="20" cellpadding="0" cellspacing="0" class="gridheader">
								<tr>
									<td width="20" style="padding-left: 4px;"><input type="checkbox" class="checkbox" onclick="SelectAll(this);"></td>
									<td class="gridspacer"><img src="/_grid/imgs/bar_line.gif"></td>
									<td width="150" class="gridheader">Field</td>
									<td class="gridspacer"><img src="/_grid/imgs/bar_line.gif"></td>
									<td width="150" class="gridheader">Condition</td>
									<td class="gridspacer"><img src="/_grid/imgs/bar_line.gif"></td>
									<td width="155" class="gridheader">Value</td>
									<td class="gridspacer"><img src="/_grid/imgs/bar_line.gif"></td>
									<td width="10">&nbsp;</td>
								</tr>
							</table>
							<div id="divSearch" style="width:100%;height:120px;overflow-y:scroll;border:1px solid #cccccc;"><crm:Search id="crmSearch" NumberFilters="4" runat="server"/></div>
						</td>
					</tr>
					<tr>
						<td align="left" style="border-bottom:1px solid #cccccc;padding-bottom:15px;padding-right:10px;">
							<button id="btnAddRow" onclick="AddSearchRow();" title="Click here to add a new row" style="width:auto">Add Row</button>
							&nbsp;
							<button id="btnDeleteRow" onclick="DeleteSearchRow();" title="Click here to delete selected rows" style="width:auto">Delete Row(s)</button>
						</td>
						<td align="right" style="border-bottom:1px solid #cccccc;padding-bottom:15px;padding-right:10px;">
							<button id="btnNewSearch" onclick="buildFetch();" title="Begin search">Go</button>
							<span>&nbsp;</span>
							<button id="btnSearch" onclick="reset();" title="Reset form">Reset</button>
							<span>&nbsp;</span>
							<button id="btnClose" onclick="window.close();" title="Close">Close</button>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<iframe id="resultFrame" src="/Search/fetchData.aspx?viewId=<%= viewId %>&objType=<%= _DefaultObjectTypeCode.ToString() %>" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
			</td>
		</tr>
	</table>
	<hr>
</body>
</html>